<template>
  <van-dialog
    :show="show"
    title=""
    destroyOnClose
    className="custom-dialog activity-dialog"
    overlay-class="activity-dialog-overlay"
    z-index="100"
    :showConfirmButton="false"
    :showCancelButton="false"
    @cancel="beforeClose"
  >
    <div class="warp">
      <div class="warp_box">
        <div class="guang"></div>
        <div class="close" @click="beforeClose">
          <NuxtImg src="/images/layout/icon-close2.png" />
        </div>
        <div class="red">
          <div class="gai">
            <NuxtImg src="/images/activity/super-red-env/red-gai.png" />
            <div class="Versao">
              <p>
                {{ lang.title }} <span>{{ lang.titleHighlight }}</span>
              </p>
            </div>
          </div>
          <div class="timer_btn">
            <p>{{ timeText }}</p>
          </div>
          <div class="dep_text2">
            <p>
              {{ lang.bonusText }}<br />
              <span>{{ lang.bonusHighlight }}</span> {{ lang.bonusSuffix }}
            </p>
          </div>
        </div>
      </div>
      <div class="RedPacketRain">
        <div class="red-packet-rain">
          <div
            v-for="p in packets"
            :key="p.id"
            class="red-packet"
            :style="{
              left: p.left,
              'animation-delay': p.delay,
              '--fall-duration': p.fallDuration,
              '--rotation-speed': p.rotationSpeed,
              '--rotation-duration': p.rotationDuration,
              width: p.widthRem,
            }"
          >
            <NuxtImg src="/images/activity/super-red-env/qian-02.png" />
          </div>
        </div>
      </div>
    </div>
  </van-dialog>
</template>

<script setup lang="ts">
const lang: any = getCurrentPageLang("activity/super-red-env");

defineProps(["show"]);
const emit = defineEmits(["changeShowSuperRedEnv"]);

const beforeClose = () => {
  emit("changeShowSuperRedEnv", false);
};

// 计时文本（示例静态展示，可接入倒计时逻辑）
const timeText = ref("11:56:14");

// 生成红包雨数据（使用百分比保证在容器内均匀分布）
function randomBetween(min: number, max: number): number {
  return Math.random() * (max - min) + min;
}

const packets = ref(
  Array.from({ length: 70 }).map((_, index) => {
    const left = `${randomBetween(-10, 100).toFixed(2)}%`;
    const delay = `${randomBetween(0.1, 5).toFixed(5)}s`;
    const fallDuration = `${randomBetween(5, 10).toFixed(6)}s`;
    const rotationSpeed = `${randomBetween(5, 6.6).toFixed(6)}s`;
    const rotationDuration = `${randomBetween(0.15, 0.2).toFixed(11)}s`;
    const widthRem = `${randomBetween(0.7, 1.7).toFixed(6)}rem`;
    return {
      id: index,
      left,
      delay,
      fallDuration,
      rotationSpeed,
      rotationDuration,
      widthRem,
    };
  })
);
</script>

<style scoped lang="scss">
.warp {
  display: flex;
  align-items: center;
  justify-content: center;
  --f2acf4be: url(/images/activity/super-red-env/red.png);
  --f2acf4ba: url(/images/activity/super-red-env/guang.png);
  --f2acf4bc: url(/images/activity/super-red-env/open.png);
  --f2acf4b8: url(/images/activity/super-red-env/timer.png);
}

.warp_box {
  width: 7.32rem;
  height: 9.14rem;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.guang {
  background: var(--f2acf4ba);
  background-repeat: no-repeat;
  background-size: 100% 100% !important;
}

@keyframes breathe {
  0%,
  100% {
    opacity: 0.5;
  }
  50% {
    opacity: 1;
  }
}

.warp_box .guang {
  width: 7.32rem;
  height: 9.14rem;
  position: absolute;
  z-index: 1;
  animation: breathe 3s ease-in-out infinite;
}

.close {
  width: 0.85rem;
  height: 0.85rem;
  background: var(--mask-color);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  right: 0.2rem;
  top: 0.2rem;
  z-index: 9;

  img {
    width: 0.4rem;
  }
}

.warp_box .red {
  width: 5.73rem;
  height: 7.55rem;
  position: relative;
  z-index: 11;
  overflow: hidden;
}

.red {
  background: var(--f2acf4be);
  background-repeat: no-repeat;
  background-size: 100% 100% !important;
}

.gai {
  width: 5.7rem;
  height: 4.63rem;
  display: flex;
  align-items: center;
  justify-items: center;

  img {
    width: 100%;
    position: absolute;
  }

  .golden,
  .rodada,
  .volte,
  .Versao {
    margin: 0 auto;
    position: relative;
    text-align: center;
    width: 4.5rem;
    height: 1.7rem;
    line-height: 0.46rem;
    font-size: 0.32rem;
    color: var(--theme-neutral1);
  }

  .Versao {
    width: 5rem;
  }

  .golden span,
  .rodada span,
  .volte span,
  .Versao span {
    font-weight: 800;
    font-size: 0.4rem;
  }
}

.timer_btn {
  width: 3.37rem;
  height: 1.1rem;
  position: relative;
  font-weight: 700;
  font-size: 0.55rem;
  color: var(--theme-dec3);
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  left: 50%;
  top: 60%;
  transform: translate(-50%, -50%);
  background: var(--f2acf4b8);
  background-repeat: no-repeat;
  background-size: 100% 100% !important;
}

.dep_text2 {
  width: 100%;
  font-weight: 400;
  font-size: 0.32rem;
  color: var(--theme-neutral1);
  text-align: center;
  position: absolute;
  bottom: 0.6rem;
  left: 50%;
  transform: translate(-50%, -50%);

  span {
    font-size: 0.46rem;
    font-weight: 600;
  }
}

.RedPacketRain {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  z-index: -1;
}

.red-packet-rain {
  position: relative;
  width: 7.32rem;
  height: 100vh;
  overflow: visible;
}

.red-packet {
  position: absolute;
  top: -1rem;
  border-radius: var(--hongbaoyue-RedPacketRain-border-radius);
  animation: fall var(--fall-duration) linear infinite,
    rotate var(--rotation-speed) linear infinite;

  img {
    width: 100%;
  }
}

@keyframes fall {
  0% {
    top: -1rem;
  }
  100% {
    top: calc(100vh + 1rem);
  }
}

@keyframes rotate {
  0% {
    transform: rotate(0);
  }
  100% {
    transform: rotate(360deg);
  }
}
</style>
